import Son from './Son'
import { useRef, useState } from 'react'
import MyContext from '../MyContext'
export default function Father() {
    const inputDom = useRef(null)
    const [transferValue, setTransferValue] = useState('')
    function transfer() {
        const inputValue = inputDom.current.value
        setTransferValue(inputValue)
    }

    function enterDo(event) {
        if (event.key === 'Enter') {
            transfer()
        }
    }

    function changeData(sonData) {
        setTransferValue(sonData)
        inputDom.current.value = sonData
    }

    return (
        <div>
            <input type='text' ref={inputDom} onKeyDown={enterDo} ></input>
            <button onClick={transfer}>传递参数</button>
            <MyContext.Provider value={transferValue}>
                <Son onChangeData={changeData} fatherData={transferValue}></Son>
            </MyContext.Provider>

        </div>
    )
}